/**********************************************************
Leo Engine - v0.1

file: leo_graphics.h
creation date: 08/05/2009
**********************************************************/

//---------------------------------------------------------
#ifndef LEO_GRAPHICS_H
#define LEO_GRAPHICS_H
//---------------------------------------------------------
#include <d3dx9.h>
#include <d3d9.h>
#include "system/System.h"
#include "../Window/Window.h"
#include "GraphicsStructs.h"
#include "VertexBuffer.h"
#include "IndexBuffer.h"
#include "Texture.h"
#include <map>
#include <windows.h>
#include "Camera.h"

#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
//------------------------------------------------

using namespace std;

namespace leo

{
//-------------------------------------
class LEO_API Graphics
{
	std::map<std::string, IDirect3DTexture9*> typedef TextureMap;
	std::map<unsigned int, IDirect3DVertexBuffer9*> typedef VertexMap;
	std::map<unsigned int, IDirect3DIndexBuffer9*> typedef IndexMap;


private:
	TextureMap texMap;
	VertexMap vexMap;
	IndexMap indMap;
	MatrixMode	currentMatMode;
	void SetupScene();
	IDirect3DDevice9* device;
	D3DDISPLAYMODE displayMode;
	//VertexBuffer<ColorVertex, COLOR_VERTEX> colorBuffer;
	//VertexBuffer<TextureVertex, TEXTURE_VERTEX> textureBuffer;

public:
	enum PrimitiveType
	{
		TRIANGLE_LIST = D3DPT_TRIANGLELIST,
		TRIANGLE_STRIP = D3DPT_TRIANGLESTRIP
	};

	bool InitDX(leo::Window* g_window);
	void Clear();
	Graphics(void);
	~Graphics(void);
	void CheckModes();
	void BeginScene(void);
	void EndScene(void);
	void Present(void);
	void Draw (const ColorVertex * _vertexCollection, PrimitiveType _prim, 
			   unsigned int _uiVertexCount);
	void Draw (const TextureVertex* _pakVertices, PrimitiveType _Prim,
			   unsigned int _uiVertexCount);
	void Draw ();
	bool Init();


	void setMatrixMode(MatrixMode _Mode);

	void translate(float _x, float _y,float _z);
	void rotateZ (float _angle);
	void scale (float _w, float _h, float _d);
	void setViewPosition (float _posX, float _posY);
	void LoadIdentity();

//---------Manejo de Texturas--------

	void LoadTexture(Texture::Ptr _tex);
	void BindTexture(Texture::Ptr _tex);
	void UnbindTexture();

//----------Buffers-----------------
	void LoadVertexBuffer(VertexBuffer<TextureVertex, TEXTURE_VERTEX> *_vexB);
	void BindVertexBuffer(VertexBuffer<TextureVertex, TEXTURE_VERTEX> *_vexB);
	void UnbidVertexBuffer();

	void LoadIndexBuffer(IndexBuffer *_indexB);
	void BindIndexBuffer(IndexBuffer *_indexB);
	void UnbidIndexBuffer();


//----------Camara------------------
	void SetCamera(Camera* _cam);
//----------------------------------
	IDirect3DDevice9* GetDevice();

//----------Luces------------------
	void init_light(void);


// current binded objects
private:
	VertexBuffer<TextureVertex, TEXTURE_VERTEX>* m_pkCurrentVB;
	IndexBuffer* m_pkCurrentIB;

};
//---------------------------------
}

#endif